function roundNumber(number, decimalPlaces) {
    var factor = Math.pow(10, decimalPlaces);
    return Math.round(number * factor) / factor;
}

function func_retail_tax_cent(retail_tax_cent, tax_rate_cent, iva_tax_cent) {
    var retail_tax_cent_adjust = '';
    if (!isNull(retail_tax_cent)) {
        // var retail_tax_cent = parseFloat(retail_tax_cent).toFixed(2)
        // 使用用户填写税率
        if (!isNull(tax_rate_cent) && tax_rate_cent !== 0) {
            var tax_rate_cent = (1 + tax_rate_cent / 100).toFixed(2)
            var retail = roundNumber(retail_tax_cent / tax_rate_cent, 2)
            var calculated_retail = roundNumber(retail * tax_rate_cent, 2)
            if (calculated_retail != retail_tax_cent) {
                // 7 次 可以调整出
                for (var i = 1; i <= 7; i++) {
                    var adjustPrice = ''
                    if (retail_tax_cent > 100) {
                        adjustPrice = (retail_tax_cent - 1 * i).toFixed(2)
                    } else {
                        adjustPrice = (retail_tax_cent - 0.1 * i).toFixed(2)
                    }

                    var retail1 = roundNumber(adjustPrice / tax_rate_cent, 2)
                    var calculated_retail1 = roundNumber(retail1 * tax_rate_cent, 2)
                    if (calculated_retail1 != adjustPrice) {
                        continue
                    }
                    retail_tax_cent_adjust = adjustPrice;
                    break
                }
            }
        }
        // 使用 系统当前税率;随意取个门店的税率
        if (isNull(tax_rate_cent) && !isNull(iva_tax_cent)) {
            var currentTax = iva_tax_cent
            if (!isNull(currentTax)) {
                var retail = roundNumber(retail_tax_cent / currentTax, 2)
                var calculated_retail = roundNumber(retail * currentTax, 2)
                if (calculated_retail != retail_tax_cent) {
                    // 7 次 可以调整出
                    for (var i = 1; i <= 7; i++) {
                        var adjustPrice = ''
                        if (retail_tax_cent > 100) {
                            adjustPrice = (retail_tax_cent - 1 * i).toFixed(2)
                        } else {
                            adjustPrice = (retail_tax_cent - 0.1 * i).toFixed(2)
                        }
                        var retail1 = roundNumber(adjustPrice / currentTax, 2)
                        var calculated_retail1 = roundNumber(retail1 * currentTax, 2)
                        if (calculated_retail1 != adjustPrice) {
                            continue
                        }
                        retail_tax_cent_adjust = adjustPrice;
                        break
                    }
                }
            }
        }
    }
    return retail_tax_cent_adjust;
}
